<?php

/**
 * Main Graphical user interface elements
 * 
 * @author Aurelijus Banelis
 */
class Design {
    /*
     * Main elements
     */
    
    /**
     * HTML code of page header
     */
    public static function header($title) {
        $title = htmlspecialchars($title);
        //FIXME: normal GUI path evaluation
        if (strpos($_SERVER['REQUEST_URI'], '/GUI/') !== false) {
            $prefix = '';
        } else {
            $prefix = 'GUI/';
        }
        echo '<?xml version="1.0" encoding="utf-8"?>' . "\n";
        ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="lt" lang="lt">
            <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
                <link rel="stylesheet" href="<?=$prefix;?>main.css" type="text/css"/>
                <script src="<?=$prefix;?>table.js" type="text/javascript"></script>
                <title><?=$title;?></title>
            </head>
            <body><div class="box">
        <?php
    }
    
    /**
     * HTML code of page footer
     */
    public static function footer($text = '') {
        if ($text) {
            $text = '<br/>' . nl2br(htmlspecialchars($text));
        }
        ?>
                    <div class="footer">Sprendimas: GRAMAsoft 2011<?=$text;?></div></div></body></html>        
        <?php
    }
    
    /**
     * HTML of tab header
     */
    public static function tabHeader($name, $command, $selected = false) {
        $name = htmlspecialchars($name);
        $command = htmlspecialchars($command);
        if ($selected) {
            $class = 'active_tab';
        } else {
            $class = 'tab';
        }
        ?> <a href="<?=$command;?>" class="<?=$class;?>"><?=$name;?></a> <?php
    }
    
    /* Html of all messages */
    public static function messages($type){
        global $error_messages;
        global $warning_messages;
        global $success_messages;
        switch($type){
            case 'error':
                $messages = $error_messages;
                if(count($messages) == 1){
                    $title = "Klaida";
                }
                else {
                    $title = "Klaidos";
                }
                break;
            case 'warning':
                $messages = $warning_messages;
                if(count($messages) == 1){
                    $title = "Perspėjimas";
                }
                else {
                    $title = "Perspėjimai";
                }
                break;
            case 'success' :
                $messages = $success_messages;
                $title = "";
                break;
            default: return;
        }
        if(count($messages) == 0){
            return;
        }
        if($title != ''){
            $title = '<div class="msg_title">'.$title.':</div>';
        }
        ?><div class="messages <?=$type;?>"><?=$title;?><ul>
        <?php
            foreach($messages as $msg){
                ?><li><?=$msg;?></li><?php
            }
        ?>
        </ul></div><?php
    }
    
    
    /*
     * Tabs
     */
    
    /**
     * HTML beginning of tabs content block
     */
    public static function tabContentBeginning() {
        ?><div><?php
    }
    
    /**
     * HTML beginning of tabs content block
     */
    public static function tabContentEnd() {
        ?></div><?php
    }
    
    
    /*
     * Menu in tabs
     */
    
    /**
     * HTML for left menu in tab content
     */
    public static function leftSubmenuBeginning($title) {
        $title = htmlspecialchars($title);
        ?>
            <div class="menu"><h2><?=$title;?></h2>
        <?php
    }
    
    /**
     * HTML for left menu in tab content
     */
    public static function leftSubmenuEnding() {
        ?></div><?php
    }
    
    /*
     * Content
     */
    
    public static function contentBeginning() {
        ?><div class="content"><?php
    }
    
    public static function contentEnding() {
        ?></div><?php
    }
    
    public static function h1($text) {
        $text = htmlspecialchars($text);
        echo "<h1>$text</h1>";
    }
}